<?php
/**
 * Created by 项目.
 * User: xuguopeng
 * Date: 2020-06-23
 * Time: 16:18
 * 洗衣订单
 */

namespace app\api\controller\v1;


use app\api\service\store\ReservationStoreOrderSer;
use app\api\service\store\SendStoreOrderSer;
use app\api\service\store\StoreOrderSer;
use app\api\validate\IdMustBePositiveInt;
use think\facade\Request;
use app\api\service\Token;
use app\api\model\StoreOrder as StoreOrderModel;

class StoreOrder
{
    // 用户下单
    public function createOrder()
    {
        $post = Request::post();
        $storeOrder = new StoreOrderSer($post);
        return $storeOrder->entrance();
    }

    // 用户订单列表
    public function getDataList()
    {
        $uid = Token::getCurrentUid();
        return StoreOrderModel::where('user_id',$uid)
            ->order('id desc')
            ->select()->toArray();
    }

    // 用户订单详情
    public function getDataInfo($id)
    {
        (new IdMustBePositiveInt())->goCheck();
        $uid = Token::getCurrentUid();
        return StoreOrderModel::with('clean')->where('id',$id)->where('user_id',$uid)->find();
    }

    // 用户预约配送时间
    public function updateOrder()
    {
        $put = Request::put();
        $reserStoreOrder = new ReservationStoreOrderSer($put);
        return $reserStoreOrder->entrance();
    }

    // 用户点击完成时间
    public function sendOrder()
    {
        $put = Request::put();
        $sendStoreOrder = new SendStoreOrderSer($put);
        return $sendStoreOrder->entrance();
    }
}